//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<painter.h>
///	@path	~/src/gui/composite/
///	@date	2008/06/04
///	@desc	Painter for composition.

#pragma once

#include "xeres.h"

#include "lib/math/color.h"

#include "gui/composite/layer.h"

namespace xeres {

	/*! 
		\class	Painter
		\brief
	*/
	class Painter
	{
	protected:
		
		friend class Composition;

		/// \ctor
		Painter( HDC dc );

		/// \ctor
		Painter( Layer * layer );

	public:

		/// \brief	Get graphics.
		Graphics& GetGraphics( void ) {
			return m_graphics;
		}

		/// \brief	Get DC.
		HDC GetDC( void ) {
			return m_hdc;
		}

		/// \brief	Get layer.
		Layer& GetLayer( void ) {
			return *m_layer;
		}

		///	\brief	Draw string, only accept single line text.
		void DrawText( const ARGB& ctext , RefWeak<StyleFont> fnt , const wchar_t * text , int len , const Rect<int>& rc , const Rect<int>& bound , UINT format );

		///	\brief	Draw string, by arranged layout.
		void DrawText( const ARGB& ctext , RefWeak<StyleFont> font , const wchar_t * text , int len , const Rect<int>& bound , const Pair<int>& pos , int * arrangement , TextStyle * style , wchar_t prev );

		/// \brief	Draw string with shadow.
		void DrawShadowText( const ARGB& ctext , const ARGB& stext , RefWeak<StyleFont> fnt , const wchar_t * text , int len , const Rect<int>& rc , const Rect<int>& bound , UINT format , int cx , int cy );

		/// \brief	Get text width.
		Rect<int> GetTextWidth( RefWeak<StyleFont> fnt , const wchar_t * text , int len , UINT format , bool shadowed , int cx = 0 , int cy = 0 );

		/// \brief	Draw layer.
		void DrawLayer( Layer * layer , const Pair<int>& pos , const Rect<int>& bound , int alpha );

		/// \brief	Draw layer.
		void DrawLayer( Layer * layer , const Pair<int>& pos , const Rect<int>& bound , const Rect<int>& sub , int alpha );

		/// \brief	Draw bitmap animation.
		void DrawBitmap( RefWeak<IBitmap> bitmap , const Pair<int>& pos , const Rect<int>& bound , int alpha , int frame = 0 );

		/// \brief	Draw bitmap animation.
		void DrawBitmap( RefWeak<IBitmap> bitmap , const Pair<int>& pos , const Rect<int>& bound , const Rect<int>& sub , int alpha , int frame = 0 );

		/// \brief	Blending frames.
		void BlendFrames( RefWeak<IBitmap> bitmap , const Pair<int>& pos , const Rect<int>& bound , int alpha , int frame1 , int frame2 , float blend );

		/// \brief	Blending frames.
		void BlendFrames( RefWeak<IBitmap> bitmap , const Pair<int>& pos , const Rect<int>& bound , const Rect<int>& sub , int alpha , int frame1 , int frame2 , float blend );
		
		/// \brief	Blur region.
		void Blur( const Rect<int>& rect , int radius );

		/// \brief	Down sample region.
		void DownSample( const Rect<int>& rect , int radius );

		// \brief	Split, tile & composite bitmap.
		void StcBitmap( RefWeak<IBitmap> bitmap , const Pair<int>& pos , const Rect<int>& bound , int alpha , int frame , int sub_w , int sub_h );

	private:

		//@ data

		// Device context.
		HDC				m_hdc;

		// Layer buffer.
		Layer *			m_layer;

		// GDI+ context.
		Graphics		m_graphics;
	};

} // namespace xeres
